<?php
namespace backend\models;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\base\Model;
use yii\web\IdentityInterface;

/**
 * Departments model
 *显示字段

 */
class Region extends ActiveRecord
{
    const STATUS_DELETED = 0;
    const STATUS_ACTIVE = 10;


    /**
     * @inheritdoc
     */
     
    public static function tableName()
    {
        return '{{%region}}';
    }
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function rules(){
        return [
            [['grade','departName','departPcount','parentId','isDelete','isEnable'],'required']
        ];
    }
    /**
     * @inheritdoc
     */
    	public function behaviors()
	{
		return [
				'timestamp' => [
						'class' => 'yii\behaviors\TimestampBehavior',
						'attributes' => [
								ActiveRecord::EVENT_BEFORE_INSERT => [
										
										
								],
								ActiveRecord::EVENT_BEFORE_UPDATE => [
										 
								] 
						] 
				] 
		];
	}

    /**
     * @inheritdoc
     */
   /* public function rules()
    {
        return [
            ['status', 'default', 'value' => self::STATUS_ACTIVE],
            ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
        ];
    }
   */

    /**
     * @inheritdoc
     */
    public static function findIdentity($id)
    {
        return static::findOne(['id' => $id]);
    }


    /**
     * Finds user by username
     *
     * @param string $username
     * @return static|null
     */
    public static function findByUsername($username)
    {
        return static::findOne(['userName' => $username]);
    }
    /**
     * 获取省份列表
     */
    public static function getProvinceList(){
        $provinceList=static::find()->where(['type'=>1])->asArray()->all();
        return $provinceList;

    }
    /**
     * 获取城市列表
     */
    public static function getCitiesList($provinceCode=110000){
        $citiesList=static::find()->where(['parentCode'=>$provinceCode])->asArray()->all();
        return $citiesList;
    }


}
